<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class Sanpham extends CI_Controller {
	protected  $language = 0;
	
	public function __construct()
	{
		parent::__construct();
		$this->load->library('parser');
		$this->load->helper('form');
		$this->load->helper(array('form', 'url'));
		$this->load->helper('language');
		$this->load->helper('html');
		$this->load->library('encrypt');
		$this->load->helper('url');
		$this->load->library('image_lib');
		$this->load->library('session');
		$this->load->library('zip');
		$this->load->library('unzip');
		$this->load->helper('url');
		$this->load->helper('xml');
	}
	
	public function index($productid=0,$cateid=0)
	{
		$data = array();
		if(isset($_SESSION['custkey']))
		{
			$custid = $_SESSION['custkey'];
			$this->load->model('customer_model');
			$data['customername'] = $this->customer_model->getcustomerbyid($custid);
		}
		$data['proid'] = $productid;
		$this->load->view('template/header',$data);
		$this->load->view('template/adventive',$data);
		$this->load->view('template/search',$data);
		$this->load->view('template/potsnews',$data);
		
		$this->load->model('news_model');
		$data['cateshow']=$this->news_model->cateshow(0);
		$data['catehide']=$this->news_model->catehide(0);
		$data['banner']=$this->news_model->banner();
		$data['newhot']=$this->news_model->newhot();
		$this->load->view('template/menuhome',$data);
		
		//title cate
		$parentcateid = $this->news_model->getparentcateid($cateid);
		$data['parentcateid']=$parentcateid;
		$parentcatename = $this->news_model->getparentcatename($cateid);
		$catename = $this->news_model->getcatename($cateid);		
		$data['catename']=$this->news_model->getcatename($cateid);
		$data['parentcatename']=$this->news_model->getparentcatename($cateid);
		$data['listcate']=$this->news_model->listcateid($cateid);
		$this->load->view('template/titlecate',$data);
				
		//left menu
		$this->load->view('template/catecontenttop',$data);
		$adventive = $this->news_model->loadadventive($productid);
		$data['adventive']=$adventive;
		if($parentcateid<=0)
		{
			$parentcateid=$cateid;
		}
		if(strlen($parentcateid)<=0)
		{
			$parentcateid=$cateid;
		}
		$data['cateid']=$cateid;
		$data['listcatep']=$this->news_model->getproductcate($parentcateid);
		$data['listproduct']=$this->news_model->getranking($parentcateid);
		$this->load->view('template/catecontentleft1',$data);
		
		//load right content
		$productinfo=$this->news_model->getproductinfo($productid);
		$catename="";
		$phone="";
		$productname="";
		$price="";
		$unit="";
		$like="";
		$imgpath="";
		$content="";
		foreach($productinfo as $row){
			$catename=$row->catename;
			$phone=$row->phone;
			$productname=$row->productname;
			$price=$row->price;
			$unit=$row->unit;
			$like=$row->like;
			$imgpath=$row->imgpath;
			$content=$row->content;
		}
		$data['catename']=$catename;
		$data['phone']=$phone;
		$data['productname']=$productname;
		$data['price']=$price;
		$data['unit']=$unit;
		$data['like']=$like;
		$data['imgpath']=$imgpath;
		$data['content']=$content;
		$data['properties']=$this->news_model->getproperties($productid);
		$data['productview']=$this->news_model->getproductview($cateid);
		$this->load->view('template/product',$data);
		$this->load->view('template/closediv',$data);
		
		$this->parser->parse('template/footer', $data,false);
		
		
	}
	
}
